package com.j2203.controller;

import com.j2203.entity.Comment;
import com.j2203.service.impl.CommentServiceImpl;
import com.j2203.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("comment")
public class CommentController {
    @Autowired(required = false)
    private CommentServiceImpl commentServic;
    //查询所有评论
    @GetMapping("select")
    public List<CommentVo> commentsele(){
        List<CommentVo> c=new ArrayList<>();
        List<Comment> commentselect = commentServic.commentselect();
        for (Comment dc:commentselect){
             c.add(new CommentVo(dc.getCid(),commentServic.gmbyid(dc.getGid()),commentServic.userbyid(dc.getUid()),dc.getContent(),dc.getLike(),dc.getCtime()));
        }
        return c;
    }
    //添加评论
    @PostMapping("add")
    public int commentadd(@RequestBody Comment comment){
        int commentadd = commentServic.commentadd(comment);
        if(commentadd==1) {
            return 1;
        }else {
            return 0;
        }
    }
    //删除评论
    @GetMapping("del")
    public int commentdel(int cid){
        int commentdel = commentServic.commentdel(cid);
        return commentdel;
    }
    //点赞
    @PostMapping("addlike")
    public int commentdel(@RequestBody Comment comment){
        int commentdel = commentServic.commentuplike(comment);
        return commentdel;
    }
}
